<template>
  <text class="number-danwei">
    {{curVal}}
  </text>
</template>
<script>
  export default {
    name: "Button",
    props:{
      increaseNum: {
        type: [Number, String],
        defalut:'',
      },
    },
    watch: {
      increaseNum() {

      }
    },
    data(){
      return{
        curVal: 0,
      }
    },
    methods:{
      numberIncrease(startNum, maxNum){
        var that = this;
        let numText = startNum;
        let golb; // 为了清除requestAnimationFrame
        function numSlideFun(){ // 数字动画
          numText += 1; // 速度的计算可以为小数 。数字越大，滚动越快
          if(numText >= maxNum){
            numText = maxNum;
            cancelAnimationFrame(golb);
          }else {
            golb = requestAnimationFrame(numSlideFun);
          }
          that.curVal=numText
        }
        numSlideFun(); // 调用数字动画
      }
    },
    mounted(){
      this.numberIncrease(0,Number(this.increaseNum));
    }
  }
</script>
<style lang="scss" scoped>

</style>